<template>
  <div>
    <div
      class="diy-body fade-show"
      :style="{
        backgroundColor: diyData.page.style.bg,
      }"
    >
      <div
        class="diy-body-custom"
        v-if="diyData.page"
        :style="[
          `padding-left:calc(750rpx - ${custom.B.right}px)`,
          `width: calc(100% - (750rpx - ${custom.B.right}px))`,
          `height:${custom.H}px`,
          diyData.page.title.style.opacity == 0
            ? `background:${diyData.page.title.style.bg};`
            : '',
        ]"
      >
        <div
          class="diy-body-custom-bar diy-body-custom-fixed"
          :style="[
            `height:${custom.B.height}px`,
            `padding-top:${custom.B.top}px`,
            `color: ${diyData.page.title.style.color}`,
            `width:calc(100% - ((750rpx - ${custom.B.right}px) * 3 + ${custom.B.width}px))`,
          ]"
        >
          <div
            class="diy-body-custom-content"
            :class="
              diyData.page.temp.value !== 1
                ? ' diy-body-custom-image '
                : diyData.page.temp.value == 1
                ? ' diy-body-custom-text-' + diyData.page.title.style.position
                : ''
            "
          >
            <image
              :src="diyData.page.title.style.img"
              v-if="diyData.page.temp.value !== 1"
              mode="aspectFill"
              :style="{
                height: `calc(${custom.H}px - ${custom.statusH}px - 30rpx)`,
                marginRight: `calc(750rpx - ${custom.B.right}px)`,
              }"
            >
            </image>
            <div
              class="diy-body-custom-text"
              :class="
                diyData.page.temp.value == 1
                  ? ' diy-body-custom-text-' + diyData.page.title.style.position
                  : ''
              "
              v-if="diyData.page.temp.value !== 3"
              :style="[pageHomeCustomText]"
            >
              {{ diyData.page.title.text }}
            </div>

            <!-- 搜索框 -->
            <div
              class="diy-body-custom-search"
              v-if="diyData.page.temp.value == 3"
              :style="[
                `width:calc(100% - 85px - ${custom.B.width != 0 ? 0 : 30}rpx)`,
                `height:calc(${custom.H}px - ${custom.statusH}px -30rpx)`,
              ]"
              @click="getSearch"
            >
              <div
                class="diy-body-custom-search-bg"
                :style="[
                  `background: ${diyData.page.title.style.search_bg}`,
                  `opacity: ${diyData.page.title.style.search_opacity / 100}`,
                  `height: ${custom.capsuleH}px`,
                  `border-radius: ${custom.capsuleH}px`,
                ]"
              ></div>
              <span class="icon icon-sousuo mr5"></span>
              <span>搜索</span>
            </div>
          </div>
        </div>
      </div>
      <div class="diy-body-group" :style="[`padding-top:${custom.H}px`]">
        <diyGroup :items="diyData.items"></diyGroup>
      </div>
    </div>
  </div>
</template>
  

<script lang="ts">
export default {
  name: "diy",
};
</script>
  <script setup lang="ts">
import {
  ref,
  getCurrentInstance,
  onMounted,
  computed,
  StyleValue,
  nextTick,
} from "vue";
import diyGroup from "@/components/diy/group.vue";
import initLoad from "@/components/ui/init-load/index.vue";
import { onShow } from "@dcloudio/uni-app";
import { diyPageDataType } from "@/types";
import { storeToRefs } from "pinia";
import { useConfig } from "@/store";
const { custom } = storeToRefs(useConfig());

const {
  proxy,
  proxy: { $utils },
} = getCurrentInstance() as any;

const props = withDefaults(
  defineProps<{
    diyData: any;
  }>(),
  {
    diyData: {},
  }
);
// 顶部Headert透明度
const topOpcity = ref<number>(1);

let systemInfo = uni.getSystemInfoSync();

// 搜索框跳转
const getSearch = () => {};

const pageHomeCustomText = computed<StyleValue>(() => {
  var style = {},
    width = 0;
  if (!props.diyData.page) return style;
  if (props.diyData.page.temp.value == 1) {
    if (
      props.diyData.page.temp.value == 1 &&
      props.diyData.page.title.style.position == "center"
    ) {
      width = custom.value.B.width || 0;
    }
    if (!props.diyData.page.title.style.position) {
      width += 15;
    }
    style = {
      width: "calc(100% - " + width + "px)",
      paddingLeft:
        props.diyData.page.title.style.position == "left"
          ? "padding-left:20rpx"
          : "0",
    };
  } else {
    if (
      props.diyData.page.temp.value == 1 &&
      props.diyData.page.title.style.position == "center"
    ) {
      width = custom.value.B.width || 0;
    }
    style = {
      width: "calc(100% - " + width + "px + 70px - 40rpx);",
    };
  }
  return style;
});

onMounted(() => {
  // toInitPageConfig();
});
</script>
  
  <style scoped>
.diy-body {
  padding-bottom: 0;
  position: relative;
  min-height: 100vh;
}
.diy-body-group {
}
.diy-body-bg {
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  z-index: -1;
}

.diy-body-custom {
  display: block;
  position: fixed;
  z-index: 99999;
}

.diy-body-custom-fixed {
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1024;
}

.diy-body-custom-bar {
  min-height: 0px;
  box-shadow: 0rpx 0rpx 0rpx;
  z-index: 9999;
  /* padding-left: 20rpx; */
  display: flex;
  align-items: center;
  z-index: 1;
}
.diy-body-custom-bar-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.diy-body-custom-content {
  align-items: center;
  display: flex;
  justify-content: space-between;
}
.diy-body-custom-content.diy-body-custom-text-center {
  justify-content: flex-end;
}
.diy-body-custom-content.end {
  justify-content: flex-end;
}
.diy-body-custom-image {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  height: 100%;
  width: 100%;
}
.diy-body-custom-image image {
  width: 180rpx;
  display: block;
}
.diy-body-custom-image .diy-body-custom-text {
}

.diy-body-custom-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 28px;
  height: 28px;
  font-size: var(--base-size-default);
}

.diy-body-custom-text-center {
  text-align: center;
  width: 100%;
}

.diy-body-custom-search {
  height: 56rpx;
  line-height: 56rpx;
  width: 240rpx;
  display: flex;
  padding: 0 20rpx;
  border-radius: 56rpx;
  position: relative;
  text-align: center;
  align-items: center;
  z-index: 1;
}

.diy-body-custom-search-bg {
  position: absolute;
  left: 0;
  width: 100%;
  border-radius: 50%;
  z-index: -1;
}

.diy-body-custom-search text {
  margin: 0 5rpx;
}
.diy-body-custom-search .icon {
  margin-right: 10rpx;
}

.diy-body-custom-collect {
  position: fixed;
  padding: 0 20rpx;
  height: 56rpx;
  line-height: 56rpx;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.7);
  font-size: var(--base-size-small-x);
  right: 20rpx;
  z-index: 9;
  border-radius: var(--base-radius-default);
  display: flex;
  z-index: 99;
}

.diy-body-custom-collect::after {
  position: absolute;
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid rgba(0, 0, 0, 0.7);
  top: -5px;
  right: 50%;
}
.diy-body-custom-collect .icon {
  font-size: var(--base-size-default);
  margin-left: 20rpx;
}

.diy-body-custom-back {
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 1000rpx;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

.diy-body-custom-back text {
  display: block;
  flex: 1;
  margin: auto !important;
  text-align: center;
  font-size: var(--base-size-large);
}

.diy-body-custom-back::before {
  content: " ";
  width: 1rpx;
  height: 110%;
  position: absolute;
  top: 22.5%;
  left: 0;
  right: 0;
  margin: auto;
  transform: scale(0.5);
  transform-origin: 0 0;
  pointer-events: none;
  box-sizing: border-box;
  opacity: 0.6;
  background-color: #ffffff;
}
</style>